import java.util.Scanner;
import java.util.Stack;

public class Test {
    public static int niBoLan(String[] tokens) {   //逆波兰求值，前提给了一个后缀表达式
        Stack<Integer> stack = new Stack<>();
        for (String x :
                tokens) {
            if (!isOperation(x)) {
                stack.push(Integer.parseInt(x));

            } else {
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch (x) {
                    case "+":
                        stack.push(num1 + num2);
                        break;
                    case "-":
                        stack.push(num1 - num2);
                        break;
                    case "*":
                        stack.push(num1 * num2);
                        break;
                    case "/":
                        stack.push(num1 / num2);
                        break;
                }
            }
        }
        return stack.pop();
    }

    public static boolean kuoHaoPiPei(String s){
        Stack<Character> stack=new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if(ch=='('||ch=='{'||ch=='['){
                stack.push(ch);
            }else{
                if(stack.empty()){  //开头是')'这种情况一定错；
                    return false;
                }
                char ch2=stack.peek();
                if(ch=='('&&ch2==ch|| ch=='{'&&ch2==ch ||ch=='['&&ch2==ch){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }
        if(!stack.empty()){  //字符串遍历完了。栈不空。括号不匹配
            return false;
        }
        return true;
    }

    public static boolean isOperation(String x) {
        if (x.equals("+") || x.equals("-") || x.equals("/") || x.equals("*")) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {

    }
}
